package com.ghj.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.ghj.dao.UserDao;
import com.ghj.pojo.User;
import com.ghj.service.UserService;
import com.ghj.utils.SaltUtils;
import org.apache.shiro.crypto.hash.Md5Hash;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class UserServiceImpl implements UserService {
    //增加用户，用于注册
    @Autowired
    private UserDao userDao;
    @Autowired
    private SaltUtils salt;

    @Override
    public int addUser(User user) {
        user.setSalt(salt.getSalt());
        String password = new Md5Hash(user.getPassword(), user.getSalt()).toBase64();
        user.setPassword(password);
        return userDao.insert(user);
    }

    @Override
    public User findOneByName(String userName) {
        QueryWrapper<User> wrapper = new QueryWrapper<>();
        wrapper.eq("user_name",userName);
        return userDao.selectOne(wrapper);
    }


}
